package org.example.facade.component;

import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.TextAlignment;

import java.util.Objects;

public class ImgLabel {
    private Image image;
    private String labelText;
    private double img_width;
    private double img_height;
    private VBox vBox;
    private ImageView imageView;
    private Pane imageWrapper;
    private Label label;


    public ImgLabel(String resource, String labelText, int img_width, int img_height){
        this.image = new Image(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(resource)),
                img_width,img_height, true, true);
        this.labelText = labelText;
        this.img_width = img_width;
        this.img_height = img_height;
    }
    public ImgLabel(String resource, String labelText){

        this(resource, labelText, 60, 60);
    }

    public VBox createVBox() {
        vBox = new VBox();
        vBox.setAlignment(Pos.CENTER);

        imageWrapper = new Pane();
        imageWrapper.setMaxSize(img_width, img_height);
        imageWrapper.setCursor(javafx.scene.Cursor.HAND);

        imageView = new ImageView(image);
        imageView.setFitHeight(img_height);
        imageView.setFitWidth(img_width);
        imageWrapper.getChildren().add(imageView);
        vBox.getChildren().add(imageWrapper);

        label = new Label(this.labelText);
        label.setPrefWidth(100);
        label.setAlignment(Pos.CENTER);
        label.setTextAlignment(TextAlignment.CENTER);
        vBox.getChildren().add(label);

        return vBox;
    }

    public ImageView getImageView() {
        return imageView;
    }

    public Pane getImageWrapper() {
        return imageWrapper;
    }

    public VBox getVBox() {
        return vBox;
    }

    public Image getImage() {
        return image;
    }

    public void setImageView(ImageView imageView) {
        this.imageView = imageView;
    }
}
